package labox.innovation.gameserver.model;

import labox.innovation.config.Config;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance.KarmaStat;
import labox.innovation.gameserver.network.SystemMessageId;
import labox.innovation.gameserver.network.serverpackets.SystemMessage;

/**
 * @author lian 关于PK的相关逻辑
 */
public class PkIntance {

	/**
	 * 和平模式
	 */
	public static final int PK_TYPE_PEACE = 0;
	/**
	 * 帮派模式
	 */
	public static final int PK_TYPE_FACTION = 1;

	/**
	 * 种族模式
	 */
	public static final int PK_TYPE_RACE = 2;
	/**
	 * 全体攻击模式
	 */
	public static final int PK_TYPE_ALL = 3;
	
	/**
	 * 家族攻击模式
	 */
	public static final int PK_CLAN=4;
	
	/**
	 * 善恶攻击模式
	 */
	public static final int PK_RIGHTEOUS=5;
	/**
	 * 当前PK模式，默認為和平模式
	 */
	private int currentPkType = 0;

	/**
	 * 是否锁定模式
	 */
	private boolean isLock;
	
	private FuzePcInstance player;

	public PkIntance(FuzePcInstance _player){
		player=_player;
	}
	public int getCurrentPkType() {
		return currentPkType;
	}

	public void setCurrentPkType(int currentPkType) {
		this.currentPkType = currentPkType;
	}
	public int isLock() {
		return isLock?1:0;
	}
	public void setLock(boolean isLock) {
		this.isLock = isLock;
	}
	/**
	 * @param target 目标对象
	 * @return
	 * 检查攻击者当前PK模式是否允许攻击目标玩家
	 */
	public boolean checkPkTypeAllowAttackable(FuzePcInstance attacker){
		//和平攻击模式
		SystemMessage msg=null;
		//和平模式
		if(attacker.getPkInstance().getCurrentPkType()==PK_TYPE_PEACE){
			msg=new SystemMessage(SystemMessageId.PK_TYPE_PEACE_CAN_NOT_ATTACK);
			attacker.sendPacket(msg);
			return false;
		}
		///帮派模式
		if(attacker.getClan()!=null&&attacker.getPkInstance().getCurrentPkType()==PK_TYPE_FACTION&&player.getClan()==attacker.getClan()){
			msg=new SystemMessage(SystemMessageId.PK_TYPE_FACTION_CAN_NOT_ATTACK);
			attacker.sendPacket(msg);
			return false;
		}
		//种族模式
		if(attacker.getPkInstance().getCurrentPkType()==PK_TYPE_RACE&&player.getRace()==attacker.getRace()){
			msg=new SystemMessage(SystemMessageId.PK_TYPE_RACE_CAN_NOT_ATTACK);
			attacker.sendPacket(msg);
			return false;
		}
		//善恶模式
		if(attacker.getPkInstance().getCurrentPkType()==PK_RIGHTEOUS&&player.getKarmaStat()==KarmaStat.ERRANTRY&&attacker.getRace()==player.getRace()){
			msg=new SystemMessage(SystemMessageId.PK_RIGHTEOUS_CAN_NOT_ATT_ERRANTRY);
			attacker.sendPacket(msg);
			return false;
		}
		//家族模式
//		if(attacker.getPkInstance().getCurrentPkType()==PK_CLAN&&player.getClan()==attacker.getClan()&&attacker.getClan()!=null){
//			msg=new SystemMessage(SystemMessageId.PK_CLAN_CAN_NOT_ATT_SAME_CLAN);
//			attacker.sendPacket(msg);
//			return false;
//		}
		if(attacker.getPkInstance().getCurrentPkType()==PK_TYPE_ALL){
			return true;
		}
		return true;
	}
	/**
	 * @param attacker
	 * @return
	 * 检测受攻击的玩家是否属于强制定义的受保护玩家
	 */
	public boolean isArbitrarilyDefined(FuzePcInstance attacker){
		SystemMessage msg=null;
		if(attacker.getLevel()<Config.PK_LEVEL_MIN){
			msg=new SystemMessage(SystemMessageId.YOU_ARE_IN_NEW_PLAYER_TIME);
			attacker.sendPacket(msg);
			return true;	
		}
		if(attacker.getParty()!=null&&player.getParty()==attacker.getParty()){
			msg=new SystemMessage(SystemMessageId.CAN_NOT_ATTACK_YOUR_FRIENDS);
			attacker.sendPacket(msg);
			return true;
		}else if(player.getLevel()<Config.PK_LEVEL_MIN){
			msg=new SystemMessage(SystemMessageId.CAN_NOT_ATTACK_NEW_PLAYER);
			attacker.sendPacket(msg);
			return true;
		}
		return false;
	}
	public String getPkTypeName(int type){
		String name="";
		switch (type) {
		case PK_TYPE_PEACE: name="和平模式";break;
		case PK_TYPE_FACTION:name="帮派模式";break;
		case PK_TYPE_RACE: name= "种族模式";break;
		case PK_TYPE_ALL: name= "全体模式";break;
		case PK_RIGHTEOUS: name= "善恶模式";break;
		case PK_CLAN: name= "家族模式";break;
		default:
			break;
		}
		return name;
	}
}
